<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 当作父子组件传参的练习，尽量掌握 -->
    <div id="app">
      <h2>vue2组件使用v-model - {{ textValue }}</h2>
      <!-- <child :value="textValue" @input="getValue"></child> -->
      <child v-model="textValue"></child>
    </div>

    <script src="./lib/vue2.js"></script>
    <script>
      const Child = {
        props: {
          value: String,
        },
        template: `
          <div>
            <span>子组件:</span>  
            <input type="text" :value="value" @input="$emit('input', $event.target.value)" />
          </div>
        `,
        // methods: {
        //   handleInput(e) {
        //     // console.log(e.target.value);
        //     this.$emit("input", e.target.value);
        //   },
        // },
      };

      new Vue({
        el: "#app",
        data() {
          return {
            textValue: "123",
          };
        },
        // methods: {
        //   getValue(val) {
        //     this.textValue = val;
        //   },
        // },
        components: {
          Child,
        },
      });
    </script>
  </body>
</html>
